home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 220 / 220.xpi / chrome / flashgot.jar / content / flashgot / XPCOM.js < prev   
Encoding:
Text File  |  2010-01-24  |  3.8 KB  |  122 lines

  1. /***** BEGIN LICENSE BLOCK *****
  2.  
  3.     FlashGot - a Firefox extension for external download managers integration
  4.     Copyright (C) 2004-2009 Giorgio Maone - g.maone@informaction.com
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.                              
  20. ***** END LICENSE BLOCK *****/
  21.  
  22. const SERVICE_CID = Components.ID(SERVICE_ID);
  23.  
  24. const SERVICE_FACTORY = {
  25.   get _instance() {
  26.     delete this._instance;
  27.     var i = new SERVICE_CONSTRUCTOR();
  28.     i.__defineGetter__("home", function() {
  29.       var f = __LOCATION__.parent;
  30.       this.__defineGetter__("home", function() { return f; });
  31.       return f;
  32.     });
  33.     return this._instance = i;
  34.   },
  35.   
  36.   createInstance: function (outer, iid) {
  37.     if (outer != null)
  38.         throw Components.results.NS_ERROR_NO_AGGREGATION;
  39.  
  40.     xpcom_checkInterfaces(iid, SERVICE_IIDS, Components.results.NS_ERROR_INVALID_ARG);
  41.     return this._instance;
  42.   }
  43. };
  44.  
  45. function xpcom_generateQI(iids) {
  46.   var lines = [];
  47.   for (var j = iids.length; j-- > 0;) {
  48.     lines.push("if(CI." + iids[j].name + ".equals(iid)) return this;");
  49.   }
  50.   lines.push("throw Components.results.NS_ERROR_NO_INTERFACE;");
  51.   return new Function("iid", lines.join("\n"));
  52. }
  53.  
  54.  
  55. function xpcom_checkInterfaces(iid,iids,ex) {
  56.   for (var j = iids.length; j-- >0;) {
  57.     if (iid.equals(iids[j])) return true;
  58.   }
  59.   throw ex;
  60. }
  61.  
  62. var Module = {
  63.   get categoryManager() {
  64.     delete this.categoryManager;
  65.     return this.categoryManager = CC['@mozilla.org/categorymanager;1'
  66.         ].getService(CI.nsICategoryManager);
  67.   },
  68.   firstTime: true,
  69.   registerSelf: function(compMgr, fileSpec, location, type) {
  70.     if (this.firstTime) {
  71.       SERVICE_CONSTRUCTOR.prototype.fileSpec = fileSpec;
  72.       compMgr.QueryInterface(CI.nsIComponentRegistrar
  73.         ).registerFactoryLocation(SERVICE_CID,
  74.         SERVICE_NAME,
  75.         SERVICE_CTRID, 
  76.         fileSpec,
  77.         location, 
  78.         type);
  79.       const catman = this.categoryManager;
  80.       for (var j = 0, len = SERVICE_CATS.length; j < len; j++) {
  81.         catman.addCategoryEntry(SERVICE_CATS[j],
  82.           SERVICE_CTRID, SERVICE_CTRID, true, true);
  83.       }
  84.       this.firstTime = false;
  85.       try {
  86.         if (fileSpec instanceof CI.nsILocalFile) {
  87.           fileSpec = fileSpec.parent;
  88.           fileSpec.append(".autoreg");
  89.           fileSpec.remove(false);
  90.         }
  91.       } catch(e) {}
  92.     }
  93.   },
  94.   
  95.   unregisterSelf: function(compMgr, fileSpec, location) {
  96.     compMgr.QueryInterface(CI.nsIComponentRegistrar
  97.       ).unregisterFactoryLocation(SERVICE_CID, fileSpec);
  98.     const catman = this.categoryManager;
  99.     for (var j = 0, len = SERVICE_CATS.length; j < len; j++) {
  100.       catman.deleteCategoryEntry(SERVICE_CATS[j], SERVICE_CTRID, true);
  101.     }
  102.   },
  103.  
  104.   getClassObject: function (compMgr, cid, iid) {
  105.     if (cid.equals(SERVICE_CID))
  106.       return SERVICE_FACTORY;
  107.   
  108.     if (!iid.equals(CI.nsIFactory))
  109.       throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  110.     
  111.     throw Components.results.NS_ERROR_NO_INTERFACE;
  112.   },
  113.  
  114.   canUnload: function(compMgr) {
  115.     return true;
  116.   }
  117. }
  118. function NSGetModule(compMgr, fileSpec) {
  119.   return Module;
  120. }
  121.  
  122.